package org.rsbot.util;

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;

public class PreferenceData
{
  private int type;
  private File file;

  public PreferenceData(int paramInt)
  {
    this.type = paramInt;
    this.file = new File(GlobalConfiguration.Paths.getSettingsDirectory() + File.separator + "pref" + paramInt + ".dat");
    try {
      if (!this.file.exists())
      {
        this.file.createNewFile();
        switch (paramInt)
        {
        case 1:
          set(new byte[] { 24, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 3, 1, 0, 1, 0, 0, 4, 8, 0, 0, 0, 127, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 4, 0, 1, 2, 0 });

          break;
        case 2:
          set(new byte[] { 1, 0, 19, 3, -38, 0, 0, 0, 1, 3, -37, 0, 0, 0, 1, 3, -30, 0, 0, 0, 2, 3, -28, -1, -1, -1, -1, 3, -27, -1, -1, -1, -1, 3, -26, -1, -1, -1, -1, 3, -25, -1, -1, -1, -1, 4, 11, 0, 0, 0, 79, 4, 12, 0, 0, 0, 74, 4, 13, -1, -1, -1, -1, 4, 28, -1, -1, -1, -1, 4, -40, 0, 0, 0, 3, 4, -6, 0, 0, 0, 67, 4, -3, 0, 0, 0, 0, 5, 35, -1, -1, -1, -1, 5, 36, -1, -1, -1, -1, 5, -122, 0, 0, 0, 1, 5, -115, -1, -1, -1, -1, 5, -107, -1, -1, -1, -1 });
        }
      }
    }
    catch (IOException localIOException)
    {
    }
  }

  public byte[] get()
  {
    try
    {
      RandomAccessFile localRandomAccessFile = new RandomAccessFile(this.file, "rw");
      byte[] arrayOfByte = new byte[(int)localRandomAccessFile.length()];
      localRandomAccessFile.readFully(arrayOfByte);

      return checkPrefs(arrayOfByte); } catch (IOException localIOException) {
    }return new byte[0];
  }

  public void set(byte[] paramArrayOfByte)
  {
    paramArrayOfByte = checkPrefs(paramArrayOfByte);
    try
    {
      RandomAccessFile localRandomAccessFile = new RandomAccessFile(this.file, "rw");
      localRandomAccessFile.write(paramArrayOfByte);
    } catch (IOException localIOException) {
    }
  }

  private byte[] checkPrefs(byte[] paramArrayOfByte) {
    switch (this.type)
    {
    case 1:
      if (paramArrayOfByte.length <= 40) {
        break;
      }
      paramArrayOfByte[19] = 3;
    }

    return paramArrayOfByte;
  }
}